package com.lingkang.flychat.controller;


import com.lingkang.flychat.dto.ResponseResult;
import com.lingkang.flychat.service.RedisService;
import com.lingkang.flychat.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private UserService userService;
    @Autowired
    private RedisService redisService;

    private String getUsername() {
        return request.getHeader("token") == null ? request.getParameter("token") : request.getHeader("token");
    }

    @GetMapping("/info")
    public ResponseResult info() {
        return userService.info(redisService.getUsernameByToken(getUsername()));
    }

    @GetMapping("/friendList")
    public ResponseResult friendList() {
        return userService.friendList(redisService.getUsernameByToken(getUsername()));
    }

}
